/*
 * Copyright 2007 - The JDPF Project Team (http://www.jdpf.org) 
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 * http://www.apache.org/licenses/LICENSE-2.0 
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 */
package org.jdpf.core.plugins.parameters;

import org.jdpf.core.kernel.exceptions.CoreException;
import org.jdpf.core.kernel.exceptions.CoreExceptionsEnum;
import org.jdpf.core.kernel.logging.ILogger;
import org.jdpf.core.kernel.logging.LoggerFactory;

/**
 * @author Paolo Ciccarese
 * @author Cristiana Larizza
 */
public abstract class AbstractParametersValidator {
	
	protected static final ILogger logger = LoggerFactory.getDefault()
		.getLogger();
	
	protected static final String MANDATORY = "Mandatory";
	protected static final String OPTIONAL = "Optional";	
	
	protected boolean logging;
	protected String pluginId;
	
	public AbstractParametersValidator(boolean logging, String pluginId) {
		this.logging = logging;
		this.pluginId = pluginId;		
	}
	
	/**
	 * It checks if the data type is allowed and returns the enumeration
	 * version of it.
	 * @param paramType	The string representing the requested type
	 * @return	The enumeration version of the requested type
	 * @throws CoreException
	 */
	protected ParametersTypesEnum parameterTypeValidation(String paramType) throws CoreException {
		return ParametersTypesEnum.getParameterType(paramType);
	}
	
	/**
	 * Mandatoriety of the parameter.
	 * @param isMandatory	Mandatory flag
	 * @return	True if the parameter is mandatory
	 * @throws CoreException
	 */
	protected boolean isParameterMandatory(String isMandatory) throws CoreException {
		if (isMandatory.equalsIgnoreCase(MANDATORY)) return true;
		else if (isMandatory.equalsIgnoreCase(OPTIONAL)) return false;
		else throw new CoreException (CoreExceptionsEnum.IllegalManifestParameters,
			"The parameter type " + isMandatory + " is not valid. Allowed " +
			"values are {" + MANDATORY + ", " + OPTIONAL + "}. ");
	}
}
